package com.longcai.piaojia.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.DayDaySignGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/11/9.
 */
public class DayDaySignAdapter extends ArrayAdapter<DayDaySignGet.SignShowEntity> {

    private Context context;
    private LayoutInflater layoutInflater;

    public DayDaySignAdapter(Context context, List<DayDaySignGet.SignShowEntity> lists) {
        super(context, 0, lists);

        layoutInflater = LayoutInflater.from(context);

        this.context = context;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;

        DayDaySignGet.SignShowEntity showEntity = getItem(position);

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_dayday_sign_list, null)));

            convertView.setTag(viewHolder);
        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }



        switch (Integer.parseInt(showEntity.is_seat)) {

            case 0:

                viewHolder.item_dayday_sign_is_seat_tv.setVisibility(View.GONE);
                viewHolder.item_dayday_sign_is_undetermined_tv.setVisibility(View.GONE);

                break;

            case 1:

                viewHolder.item_dayday_sign_is_seat_tv.setVisibility(View.VISIBLE);
                viewHolder.item_dayday_sign_is_undetermined_tv.setVisibility(View.GONE);

                break;

            case 2:

                viewHolder.item_dayday_sign_is_seat_tv.setVisibility(View.GONE);
                viewHolder.item_dayday_sign_is_undetermined_tv.setVisibility(View.VISIBLE);

                break;

        }

        switch (Integer.parseInt(showEntity.status)) {

            case 0:

                viewHolder.item_dayday_sign_is_book_state_tv.setTextColor(ContextCompat.getColor(context, R.color.hint_color));
                viewHolder.item_dayday_sign_is_book_state_tv.setBackgroundResource(R.drawable.item_mycollection_nostart_text_bg);
                viewHolder.item_dayday_sign_is_book_state_tv.setText(context.getResources().getString(R.string.goods_info_status_notstart_text));

                break;
            case 1:

                viewHolder.item_dayday_sign_is_book_state_tv.setTextColor(ContextCompat.getColor(context, R.color.item_mycollection_money_text_color));
                viewHolder.item_dayday_sign_is_book_state_tv.setBackgroundResource(R.drawable.item_mycollection_ordering_text_bg);
                viewHolder.item_dayday_sign_is_book_state_tv.setText(context.getResources().getString(R.string.goods_info_status_ordering_text));

                break;
            case 2:

                viewHolder.item_dayday_sign_is_book_state_tv.setTextColor(ContextCompat.getColor(context, R.color.item_mycollection_sale_text_color));
                viewHolder.item_dayday_sign_is_book_state_tv.setBackgroundResource(R.drawable.item_mycollection_sale_text_bg);
                viewHolder.item_dayday_sign_is_book_state_tv.setText(context.getResources().getString(R.string.goods_info_status_selling_text));

                break;
            case 3:

                viewHolder.item_dayday_sign_is_book_state_tv.setTextColor(ContextCompat.getColor(context, R.color.hint_color));
                viewHolder.item_dayday_sign_is_book_state_tv.setBackgroundResource(R.drawable.item_mycollection_nostart_text_bg);
                viewHolder.item_dayday_sign_is_book_state_tv.setText(context.getResources().getString(R.string.goods_info_status_sellout_text));

                break;

        }



        GlideLoader.getInstance().get(context, showEntity.picurl, viewHolder.item_dayday_sign_iv, R.mipmap.goods);

        viewHolder.item_dayday_sign_tilte_tv.setText(showEntity.title);
        viewHolder.item_dayday_sign_time_tv.setText(context.getString(R.string.item_mycollection_time_text) + showEntity.start_time);
        viewHolder.item_dayday_sign_address_tv.setText(context.getString(R.string.item_mycollection_address_text) + showEntity.place_name);



        return convertView;
    }


    class ViewHolder {

        @BoundView(R.id.item_dayday_sign_iv) private ImageView item_dayday_sign_iv;

        @BoundView(R.id.item_dayday_sign_tilte_tv) private TextView item_dayday_sign_tilte_tv;
        @BoundView(R.id.item_dayday_sign_time_tv) private TextView item_dayday_sign_time_tv;
        @BoundView(R.id.item_dayday_sign_address_tv) private TextView item_dayday_sign_address_tv;

        @BoundView(R.id.item_dayday_sign_is_seat_tv) private TextView item_dayday_sign_is_seat_tv;
        @BoundView(R.id.item_dayday_sign_is_undetermined_tv) private TextView item_dayday_sign_is_undetermined_tv;
        @BoundView(R.id.item_dayday_sign_is_book_state_tv) private TextView item_dayday_sign_is_book_state_tv;
    }


}
